
import 'package:flutter/material.dart';

void main() =>runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context){
    return MaterialApp(
        home:HYHomePage()
    );
  }
}

class HYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context){
    return Scaffold(
      appBar: AppBar(
        title: Text("基础widget"),
      ),
      body:HYHomeContent(),
    );
  }
}

class HYHomeContent extends StatefulWidget {
  const HYHomeContent({super.key});

  @override
  State<HYHomeContent> createState() => _HYHomeContentState();
}
/**
 * 编辑器快捷键配置
 * preferences>keymap>找到冲突的快捷键extract，修改快捷键
 *alt+z抽取成一个widget
 *
 */
class _HYHomeContentState extends State<HYHomeContent> {
  final usernameTextEditController = TextEditingController();
  final passwordTextEditController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return TextFiedldDemo(usernameTextEditController: usernameTextEditController, passwordTextEditController: passwordTextEditController);
  }
}

class TextFiedldDemo extends StatelessWidget {
  const TextFiedldDemo({
    super.key,
    required this.usernameTextEditController,
    required this.passwordTextEditController,
  });

  final TextEditingController usernameTextEditController;
  final TextEditingController passwordTextEditController;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(8.0),
      child: Column(
        children: <Widget>[
          TextField(
            controller: usernameTextEditController,
            decoration: InputDecoration(
              labelText: 'username',
              icon: Icon(Icons.people),
              hintText: '请输入用户名',
              border: OutlineInputBorder(),
              filled: true,
              fillColor: Colors.red[100]
            ),
            onChanged: (val){
              print(val);
            },
            onSubmitted: (val){
             print("submint:$val");
            },
          ),
          SizedBox(height: 10),
          TextField(
            controller: passwordTextEditController,
            decoration: InputDecoration(
              labelText: "password",
              icon: Icon(Icons.lock),
              border: OutlineInputBorder(),
            ),
          ),
          SizedBox(height: 10),
          Container(
            width: double.infinity,
            height: 56,
            child:ElevatedButton(
              child: Text('登陆',
                  style: TextStyle(fontSize: 20,color: Colors.white)
              ),
              onPressed: (){
                //1.获取用户名和密码
                final username = usernameTextEditController.text;
                final password = passwordTextEditController.text;
                print('账号：$username 密码：$password');
              },
            ),
          )
        ],
      ),
    );
  }
}

